****TABLE 1****

cd "$main_dir/output/tables/main"

global basic 	sex marital religion edu

//--------------------------------------------------------
//Read in relevant datasets
//--------------------------------------------------------

clear
use "$data_dir/clean/harmonized_dataset.dta"

merge m:1 ccode survey_year yob using "$data_dir/raw/lifeexp_variables_data/growth_rate_mpd_var_exp.dta", nogen keepusing(total_growth_rate_obs wgrowth_rate_1 yob_ln_gdppc)

fegen ccode_survey_year = group(ccode survey_year)
fegen subregion_yob = group(subregion yob) if yob!=-99
fegen ccode_age = group(ccode age) if age!=-99
fegen svy_survey_year = group(survey_year survey)

cap drop sample gallup_sample
gen sample = 1 if born_country!=0 & total_growth_rate_obs>=0.9*(age-1) & total_growth_rate_obs!=.
gen gallup_sample = 1 if born_country==1 & total_growth_rate_obs>=0.9*(age-1) & total_growth_rate_obs!=. & survey=="Gallup"
replace gallup_sample = 1 if total_growth_rate_obs>=0.9*(age-1) & total_growth_rate_obs!=. & survey=="Gallup" & (born_country!=0) & survey_year==2006

//--------------------------------------------------------
//Create Table 1
//--------------------------------------------------------

//Column 1
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if sample==1, absorb(ccode svy_survey_year subregion_yob age $basic) cluster(ccode)
cap drop z*
local varlist trust_govt wgrowth_rate_1 yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}													   
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if sample==1, absorb(ccode svy_survey_year subregion_yob age $basic) cluster(ccode)
outreg2 using table_1.doc, replace dec(3) nocons addtext(Country FE, Yes, ///
													    Age FE, Yes, ///
														Survey Year FE x Survey FE, Yes, ///
														Subcontinent FE x Cohort FE, Yes, ///
													    Country FE x Survey Year FE, No, ///
														Country FE x Age FE, No, ///
													    Survey, Harmonized) keep(zwgrowth_rate_1) 

//results interpretation
qui summ trust_govt if e(sample)==1 & ccode=="ITA"
qui scalar beta_ita = _b[zwgrowth_rate_1]*r(sd)
qui summ trust_govt if e(sample)==1 & ccode=="ITA" & cohort=="1950s"
qui scalar trust_ita_50s = r(mean)
qui summ trust_govt if e(sample)==1 & ccode=="ITA" & cohort=="1990s"
qui scalar trust_ita_90s = r(mean)
di abs(beta_ita)/(abs(trust_ita_50s-trust_ita_90s))
summ wgrowth_rate_1 if e(sample)==1 & ccode=="ITA"

qui summ trust_govt if e(sample)==1 & ccode=="IND"
qui scalar beta_ind = _b[zwgrowth_rate_1]*r(sd)
qui summ trust_govt if e(sample)==1 & ccode=="IND" & cohort=="1950s"
qui scalar trust_ind_50s = r(mean)
qui summ trust_govt if e(sample)==1 & ccode=="IND" & cohort=="1990s"
qui scalar trust_ind_90s = r(mean)
di abs(beta_ind)/(abs(trust_ind_50s-trust_ind_90s))
summ wgrowth_rate_1 if e(sample)==1 & ccode=="IND"														

//Column 2
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if sample==1, absorb(ccode_survey_year svy_survey_year subregion_yob age $basic) cluster(ccode)
cap drop z*
local varlist trust_govt wgrowth_rate_1 yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}													   
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if sample==1, absorb(ccode_survey_year svy_survey_year subregion_yob age $basic) cluster(ccode)
outreg2 using table_1.doc, append dec(3) nocons addtext(Country FE, No, ///
													    Age FE, Yes, ///
														Survey Year FE x Survey FE, Yes, ///
														Subcontinent FE x Cohort FE, Yes, ///
													    Country FE x Survey Year FE, Yes, ///
														Country FE x Age FE, No, ///
													    Survey, Harmonized) keep(zwgrowth_rate_1) 

//Column 3
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if sample==1, absorb(ccode_survey_year ccode_age svy_survey_year subregion_yob $basic) cluster(ccode)
cap drop z*
local varlist trust_govt wgrowth_rate_1 yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}													   
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if sample==1, absorb(ccode_survey_year ccode_age svy_survey_year subregion_yob $basic) cluster(ccode)
outreg2 using table_1.doc, append dec(3) nocons addtext(Country FE, No, ///
													    Age FE, No, ///
														Survey Year FE x Survey FE, Yes, ///
														Subcontinent FE x Cohort FE, Yes, ///
													    Country FE x Survey Year FE, Yes, ///
														Country FE x Age FE, Yes, ///
													    Survey, Harmonized) keep(zwgrowth_rate_1) 

//Column 4
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if gallup_sample==1, absorb(ccode svy_survey_year subregion_yob age $basic) cluster(ccode)
cap drop z*
local varlist trust_govt wgrowth_rate_1 yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}													   
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if gallup_sample==1, absorb(ccode svy_survey_year subregion_yob age $basic) cluster(ccode)
outreg2 using table_1.doc, append dec(3) nocons addtext(Country FE, Yes, ///
													    Age FE, Yes, ///
														Survey Year FE x Survey FE, Yes, ///
														Subcontinent FE x Cohort FE, Yes, ///
													    Country FE x Survey Year FE, No, ///
														Country FE x Age FE, No, ///
													    Survey, Gallup) keep(zwgrowth_rate_1) 	

//Column 5
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if gallup_sample==1, absorb(ccode_survey_year subregion_yob age $basic) cluster(ccode)
cap drop z*
local varlist trust_govt wgrowth_rate_1 yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}													   
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if gallup_sample==1, absorb(ccode_survey_year subregion_yob age $basic) cluster(ccode)
outreg2 using table_1.doc, append dec(3) nocons addtext(Country FE, No, ///
													    Age FE, Yes, ///
														Survey Year FE x Survey FE, No, ///
														Subcontinent FE x Cohort FE, Yes, ///
													    Country FE x Survey Year FE, Yes, ///
														Country FE x Age FE, No, ///
													    Survey, Gallup) keep(zwgrowth_rate_1) 															

//Column 6
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if gallup_sample==1, absorb(ccode_survey_year ccode_age subregion_yob $basic) cluster(ccode)
cap drop z*
local varlist trust_govt wgrowth_rate_1 yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}													   
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if gallup_sample==1, absorb(ccode_survey_year ccode_age subregion_yob $basic) cluster(ccode)
outreg2 using table_1.doc, append dec(3) nocons addtext(Country FE, No, ///
													    Age FE, No, ///
														Survey Year FE x Survey FE, No, ///
														Subcontinent FE x Cohort FE, Yes, ///
													    Country FE x Survey Year FE, Yes, ///
														Country FE x Age FE, Yes, ///
													    Survey, Gallup) keep(zwgrowth_rate_1) 		
